package DB_Manage;

import java.util.ArrayList;
import scheduler.AuthenticationPair;
import scheduler.IdentifierPair;


/**
 * This class is used to create user objects. It contains the user's 
 * APS site ID, their encrypted password, generic user data and a list of 
 * scrape jobs corresponding to the billing sites the user is registered for.
 * @author Johann Jungbauer
 */
public class User {
  
    private String _UserID;
    private String _SitePW;
    private String _FirstName;
    private String _Surname;
    private String _EmailAddress;
    private String _IDNumber;
    private String _PhoneNumber;
    private String _DateOfBirth;
    private ArrayList<JobData> _Jobs = new ArrayList<JobData>(); 

    public User(String id, String pw, String fName, String surname, String email,
            String idNum, String phone, String dob)
    {
        setUserID(id);
        setSitePW(pw);
        setFirstName(fName);
        setSurname(surname);
        setEmail(email);
        setIDNumber(idNum);
        setPhone(phone);
        setDateOfBirth(dob);
    }
    
    public void addJob(JobData job)
    {
        JobData add = job;
        _Jobs.add(add);
    }
    
    public void addJobs(ArrayList<JobData> jobs)
    {
        _Jobs = jobs;
    }
    
    public void removeJob(String billingRef)
    {
        int pos = 0;

        while(pos < _Jobs.size())
        {
            if(_Jobs.get(pos).getBillingSiteRef().compareTo(billingRef) == 0)
            {
                _Jobs.remove(pos);
            }
            pos++;
        }

    }
    
    public ArrayList<JobData> getJobs()
    {
        return _Jobs;
    }
    
    public void setSitePW(String pw)
    {
        _SitePW = pw;
    }
    
    public void setFirstName(String name)
    {
        _FirstName = name;
    }
    
    private void setUserID(String id)
    {
        _UserID = id;
    }
    
    public void setSurname(String surname)
    {
        _Surname = surname;
    }
    public void setEmail(String email)
    {
        _EmailAddress = email;
    }
    public void setIDNumber(String idNum)
    {
        _IDNumber = idNum;
    }
    public void setPhone(String phone)
    {
        _PhoneNumber = phone;
    }
    public void setDateOfBirth(String dob)
    {
        _DateOfBirth = dob;
    }
    
    public String getSitePW()
    {
        return _SitePW;
    }
    
    public String getFirstName()
    {
        return _FirstName;
    }
    
    public String getUserID()
    {
        return _UserID;
    }
    
    public String getSurname()
    {
        return _Surname;
    }
    public String getEmailAddress()
    {
        return _EmailAddress;
    }
    public String getIDNumber()
    {
        return _IDNumber;
    }
    public String getPhoneNumber()
    {
        return _PhoneNumber;
    }
    public String getDateOfBirth()
    {
        return _DateOfBirth;
    }
    
    /**
     * Used to print the data in the object to System.out.
     * @param
     */
    public void printUser()
    {
        System.out.println(_UserID);
        System.out.println(_SitePW);
        System.out.println(_FirstName);
        
        System.out.println(_Jobs.size());
        
        for(int i = 0; i < _Jobs.size(); i++)
        {
            System.out.println(_Jobs.get(i).getBillingSiteRef());
            System.out.println(_Jobs.get(i).getStatus());
            System.out.println(_Jobs.get(i).getLatestResult());
            
            AuthenticationPair atemp[] = _Jobs.get(i).getAuthenticationPairs();
            IdentifierPair itemp[] = _Jobs.get(i).getIdentifierPairs();
            
            for(int x = 0; x < 5; x++)
            {
                System.out.println(atemp[x].getText());
                System.out.println(atemp[x].getValue());
            }
            for(int x = 0; x < 5; x++)
            {
                System.out.println(itemp[x].getText());
                System.out.println(itemp[x].getValue());
            }
        }
    }
}
